package com.lsp.microorder.recharge.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class DelayConfig {


    // 延迟队列
    @Bean
    public Queue orderDelayQueue() {
        return new Queue("order_queue1");
    }

    // 订单交换机
    @Bean
    public CustomExchange orderDelayExchange() {
        String type = "x-delayed-message";
        return new CustomExchange("order_delay_ex", type,
                true,
                false,
                new HashMap<String, Object>() {{
            put("x-delayed-type", "direct");
        }});
    }

    // 延迟队列和延迟交换机绑定
    @Bean
    public Binding orderDelayBinding(Queue orderDelayQueue, CustomExchange orderDelayExchange) {
        return BindingBuilder.bind(orderDelayQueue).to(orderDelayExchange).with("order_delay_key").noargs();
    }

}
